package com.jmxcfc.blfsc.jiwei.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.math.BigInteger;
import java.security.MessageDigest;

/**
 * Created by xyyou
 * 2023/10/23 9:26
 */
@Slf4j
public class MD5Util {

    /**
     * md5加密一（Java自身包实现-32位小写加密）
     * @param str
     * @return
     */
    public static String md5(String str) {
        byte[] secretBytes ;
        try {
            secretBytes = MessageDigest.getInstance("md5").digest(
                    str.getBytes());
        } catch (Exception e) {
            throw new RuntimeException("没有这个md5算法！");
        }
        String md5code = new BigInteger(1, secretBytes).toString(16);
        int length = md5code.length();
        for (int i = 0; i < 32 - length; i++) {
            //md5code = "0" + md5code;
            md5code = StringUtils.join("0", md5code);
        }
        log.info("md5code:{}",md5code);
        return md5code;
    }

    public static void main(String[] args) {
        //String test = "jm0828w7f7sl8298-5374258-dcbf85-c87e5-9c1ae6-bfg69";
        String test = "jm0919f033uiSMS_SC011750709167434194944";
        String encrptString = MD5Util.md5(test);
        log.info("encrptString:{}",encrptString);
        log.info("current:{}", System.currentTimeMillis());
    }
}
